﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ColorBox4Sitecore.Colorbox;
using ColorBox4Sitecore.Helpers;
using ColorBox4Sitecore.Pipelines;
using ColorBox4Sitecore.RessourcesRegistation;
using Sitecore.Pipelines;

namespace ColorBox4Sitecore.UI.sitecore_modules.Web.Colorbox4Sitecore.UserControls
{
    public partial class Colorbox4Sitecore : SublayoutBase
    {
        //TODO : Handle the ' in the string JS

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void HandleAddHeaderJavascript()
        {            
            AddHeaderRessourcesArgs args = new AddHeaderRessourcesArgs();
            CorePipeline.Run("colorbox4sitecore_addheaderjs", args);
            RessourceRegistrator.RegisterRessources(this.Page, args.RessourceList);
        }

        private void LoadConfig(ColorboxControl ctl)
        {
            try
            {
                ctl.Config = new ColorboxSitecore(this.DataSourceItem);
            }
            catch (NullReferenceException)
            {
                lError.Text = Sitecore.Context.PageMode.IsNormal ? ColorboxTranslateHelper.Translate("Datasource Not Set") : ColorboxTranslateHelper.Translate("Datasource Not Set Admin");
            }
        }
    }
}